package com.heyqing.topic.CountBits_0338;

/**
 * ClassName:CountBits
 * Package:com.heyqing.topic.CountBits_0338
 * Description:
 *
 * @Date:2024/9/27
 * @Author:Heyqing
 */
public class CountBits {
    public int[] countBits(int n) {
        int[] result = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            int t = i;
            int count = 0;
            for (int j = 0; j < 17; j++) {
                if ((t & 1) == 1) count++;
                t >>= 1;
            }
            result[i] = count;
        }
        return result;
    }
}
